package com.example.learningspringboot.controller;

import com.example.learningspringboot.service.Test1Service;
import com.example.learningspringboot.service.Test2Service;
import com.example.learningspringboot.service.Test3Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 测试控制器
 * 该类演示了如何使用 Spring 的依赖注入来管理服务层的组件。
 * 通过构造器注入方式，确保所有依赖都被正确注入。
 */
@Controller
@RequestMapping("/testConstructor")
public class TestConstructorController {

    private final Test1Service test1Service;
    private final Test2Service test2Service;
    private final Test3Service test3Service;

    // 使用构造器注入，推荐的方式
    @Autowired
    public TestConstructorController(Test1Service test1Service, Test2Service test2Service, Test3Service test3Service) {
        this.test1Service = test1Service;
        this.test2Service = test2Service;
        this.test3Service = test3Service;
    }

    @GetMapping("/test1")
    @ResponseBody
    public String test1() {
        test1Service.test();
        test2Service.test();
        test3Service.test();
        return "test1";
    }
}
